package com.apes.fico.masterdata.store.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.util.ApesConst;
import com.apes.framework.util.DateUtil;
import com.apes.scm.masterdata.enumeration.model.Enumeration;
import com.apes.scm.masterdata.frame.model.Dept;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.util.Date;

/**
 * @program: apes-server
 * @description: 类店
 * @author: czs
 * @create: 2023-03-23 11:25
 **/
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = TypeStore.CONST_TABLE_NAME)
public class TypeStore extends Model {

    public static final String CONST_TABLE_NAME = "MAS_TYPE_STORE";

    @Id
    @Column(name = "id")
    @ApesGenerator(code = CONST_TABLE_NAME, name = "同类店编码",padding = 8)
    private String id;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "dept_id", referencedColumnName = "id")
    @Comment("门店")
    private Dept dept;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "type_store", referencedColumnName = "id")
    @Comment("门店类型")
    private Enumeration typeStore;

    @JSONField(format = DateUtil.SHOW_MONTH_FORMAT)
    @Temporal(TemporalType.TIMESTAMP)
    @NotNull
    @Column(name = "year_month")
    @Comment("年月")
    private Date yearMonth;

    @Column(name = "tasks_amt", nullable = false, columnDefinition = ApesConst.FIELD_QTY_16_4_0)
    @Comment("经营任务(元)")
    private double tasksAmt = 0;

    @Column(name = "tasks_type")
    @Comment("任务类型")
    private String tasksType; //business:营业额;grossProfit:毛利额

    @JSONField(format = DateUtil.SHOW_DATETIME_FORMAT)
    @Temporal(TemporalType.TIMESTAMP)
    @NotNull
    @Column(name = "valid_date")
    @Comment("生效日期")
    private Date validDate;

    @Column(name = "valid", nullable = false, columnDefinition = "number(1,0) default 1")
    @Comment("有效标记")
    private boolean valid = true; //有效
}
